From 3c34ca3405f852b554bc05e07e460dbe9b9eae59 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 5 Nov 2014 15:19:00 +0100 Subject: [PATCH] gdkgl: Don't constantly re-create the tmp framebuffer --- gdk/gdkgl.c | 15 +++++++++------ gdk/gdkglcontext.c | 23 +++++++++++++++++++++++ gdk/gdkglcontextprivate.h | 9 +++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c index eaf1112794..c7c847a0fc 100644 --- a/gdk/gdkgl.c +++ b/gdk/gdkgl.c @@ -86,9 +86,10 @@ gdk_cairo_draw_from_gl (cairo_t *cr, gboolean trivial_transform; cairo_surface_t *group_target; GdkWindow *direct_window, *impl_window; - GLuint framebuffer; - GLint alpha_size = 0; + guint framebuffer; + int alpha_size = 0; cairo_region_t *clip_region; + GdkGLContextPaintData *paint_data; impl_window = window->impl_window; @@ -104,6 +105,10 @@ gdk_cairo_draw_from_gl (cairo_t *cr, clip_region = gdk_cairo_region_from_clip (cr); gdk_gl_context_make_current (context); + paint_data = gdk_gl_context_get_paint_data (context); + + if (paint_data->tmp_framebuffer == 0) + glGenFramebuffersEXT (1, &paint_data->tmp_framebuffer); if (source_type == GL_RENDERBUFFER) { @@ -150,7 +155,7 @@ gdk_cairo_draw_from_gl (cairo_t *cr, /* Create a framebuffer with the source renderbuffer and make it the current target for reads */ - glGenFramebuffersEXT (1, &framebuffer); + framebuffer = paint_data->tmp_framebuffer; glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, framebuffer); glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, source); @@ -213,7 +218,6 @@ gdk_cairo_draw_from_gl (cairo_t *cr, glDisable (GL_SCISSOR_TEST); glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0); - glDeleteFramebuffersEXT (1, &framebuffer); #undef FLIP_Y @@ -353,7 +357,7 @@ gdk_cairo_draw_from_gl (cairo_t *cr, cairo_surface_set_device_scale (image, buffer_scale, buffer_scale); #endif - glGenFramebuffersEXT (1, &framebuffer); + framebuffer = paint_data->tmp_framebuffer; glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, framebuffer); if (source_type == GL_RENDERBUFFER) @@ -378,7 +382,6 @@ gdk_cairo_draw_from_gl (cairo_t *cr, glPixelStorei (GL_PACK_ROW_LENGTH, 0); glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0); - glDeleteFramebuffersEXT (1, &framebuffer); cairo_surface_mark_dirty (image); diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c index 697eb2ffa3..1628e51ced 100644 --- a/gdk/gdkglcontext.c +++ b/gdk/gdkglcontext.c @@ -87,6 +87,7 @@ typedef struct { guint realized : 1; guint use_texture_rectangle : 1; + GdkGLContextPaintData *paint_data; } GdkGLContextPrivate; enum { @@ -126,6 +127,15 @@ gdk_gl_context_dispose (GObject *gobject) G_OBJECT_CLASS (gdk_gl_context_parent_class)->dispose (gobject); } +static void +gdk_gl_context_finalize (GObject *gobject) +{ + GdkGLContext *context = GDK_GL_CONTEXT (gobject); + GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context); + + g_clear_pointer (&priv->paint_data, g_free); +} + static void gdk_gl_context_set_property (GObject *gobject, guint prop_id, @@ -286,6 +296,7 @@ gdk_gl_context_class_init (GdkGLContextClass *klass) gobject_class->set_property = gdk_gl_context_set_property; gobject_class->get_property = gdk_gl_context_get_property; gobject_class->dispose = gdk_gl_context_dispose; + gobject_class->finalize = gdk_gl_context_finalize; g_object_class_install_properties (gobject_class, LAST_PROP, obj_pspecs); } @@ -319,6 +330,18 @@ gdk_gl_context_end_frame (GdkGLContext *context, GDK_GL_CONTEXT_GET_CLASS (context)->end_frame (context, painted, damage); } +GdkGLContextPaintData * +gdk_gl_context_get_paint_data (GdkGLContext *context) +{ + + GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context); + + if (priv->paint_data == NULL) + priv->paint_data = g_new0 (GdkGLContextPaintData, 1); + + return priv->paint_data; +} + gboolean gdk_gl_context_use_texture_rectangle (GdkGLContext *context) { diff --git a/gdk/gdkglcontextprivate.h b/gdk/gdkglcontextprivate.h index fcb82a8345..cf6e5785b3 100644 --- a/gdk/gdkglcontextprivate.h +++ b/gdk/gdkglcontextprivate.h @@ -54,6 +54,15 @@ void gdk_gl_context_end_frame (GdkGLContext *context, cairo_region_t *painted, cairo_region_t *damage); + + +typedef struct { + guint tmp_framebuffer; +} GdkGLContextPaintData; + +GdkGLContextPaintData *gdk_gl_context_get_paint_data (GdkGLContext *context); + + G_END_DECLS #endif /* __GDK_GL_CONTEXT_PRIVATE_H__ */ -- 2.30.2